<?php

namespace app\admin\controller;

use think\facade\Request;
use app\common\Error;
use app\common\Common;
use app\admin\service\AllianceService;

// cps联盟统计
class Alliance extends Base
{
    private $service;

    public function __construct(AllianceService $service)
    {
        parent::__construct();
        $this->service = $service;
    }

    // 渲染推广链接页面
    public function linkIndex()
    {
        return view();
    }

    // 渲染推广主列表页面
    public function mainIndex()
    {
        return view();
    }

    // 推广链接列表
    public function linkList()
    {
        $params = Request::param();

        $data = $this->service->getPromotionLinkList($params);
        if (!empty($data['message'])) {
            return Common::fail($data['message']);
        }

        return Common::success($data);
    }

    // 修改总花费
    public function editSpend()
    {
        $params = Request::param();

        try {
            validate(\app\admin\validate\Alliance::class)->scene('edit_spend')->check($params);
        } catch (\Exception $e) {
            return Common::fail($e->getError());
        }

        $result = $this->service->editSpend($params);

        return $result ? Common::success() : Common::fail();
    }

    // 公众号(推广主)列表
    public function mainList()
    {
        $params = Request::param();

        $data = $this->service->getPromotionMainList($params);

        return Common::success($data);
    }

    // 渲染查看收入页面
    public function revenue()
    {
        return view();
    }

    // 查看收入
    public function viewRevenue()
    {
        $params = Request::param();

        try {
            validate(\app\admin\validate\Alliance::class)->scene('view_revenue')->check($params);
        } catch (\Exception $e) {
            return Common::fail($e->getError());
        }

        $data = $this->service->viewRevenue($params);
        return Common::success($data);
    }

    // 渲染查看用户页面
    public function user()
    {
        return view();
    }

    // 查看用户
    public function viewUser()
    {
        $params = Request::param();

        try {
            validate(\app\admin\validate\Alliance::class)->scene('view_user')->check($params);
        } catch (\Exception $e) {
            return Common::fail($e->getError());
        }

        $data = $this->service->viewUser($params);
        return Common::success($data);
    }
}